package com.easyfun.healthmagicbox.inputviews;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.TextView;

import com.easyfun.healthmagicbox.R;
import com.easyfun.healthmagicbox.ViewPagerActivity;
import com.easyfun.healthmagicbox.base.BaseActivity;
import com.easyfun.healthmagicbox.base.DatabaseAccess;
import com.easyfun.healthmagicbox.base.DatabaseAccessImplementation;
import com.easyfun.healthmagicbox.ormlite.DatabaseHelper;
import com.easyfun.healthmagicbox.ormlite.DiseaseTypeEnum;
import com.easyfun.healthmagicbox.pojo.ConstantData;
import com.easyfun.healthmagicbox.pojo.DoctorProfile;
import com.easyfun.healthmagicbox.pojo.DoctorAndHospital;
import com.easyfun.healthmagicbox.util.ImageTools;
import com.easyfun.healthmagicbox.util.URIConverter;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.GenericRawResults;
import com.j256.ormlite.dao.RawRowMapper;

public class DoctorLinkActivity extends BaseActivity implements DatabaseAccess {

	
	class docter {
		String doctername;
		String docterdecription;

		public docter(String a, String b) {
			doctername = a;
			docterdecription = b;
		}
	}

	private ImageView doc_image;
	private TextView doc_txtIntroduction;

	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.doctorlinklayout);
		// personal ID
		if (!checkPersonId())
		{
			return;
		}
		if (!checkDoctorId())
		{
			return;
		}

		loadDocInfo();

	}
	
	private void loadDocInfo() {
		doc_image = (ImageView) findViewById(R.id.doc_image);
		doc_txtIntroduction = (TextView) findViewById(R.id.doc_txtIntroduction);
		try {
			Dao<DoctorProfile, Integer> doctorProfileDao = 
					getHelper(this).getDoctorProfileDao();
			List<DoctorProfile> doctors = doctorProfileDao.queryForEq("doctorID", m_doctorid);
			if (doctors.size() == 1)
			{
				String name = doctors.get(0).getDoctorName();
				String dochos = doctors.get(0).getDoctorHospital();
				doc_txtIntroduction.setText(name +" "+
						dochos +" " +doctors.get(0).getDoctorIntroduction());
				String docFilename = doctors.get(0).getDoctorPictureFile();
				Bitmap bm = null;
				if ((docFilename==null)||(docFilename.length()==0))
				{
					bm = ImageTools.createTextBitmap(this, 160, 160, 5, 6, 
							5,doctors.get(0).getDoctorName(),"");
				}else
					bm = URIConverter.getDoctorHeadFromAppSDCard(DoctorLinkActivity.this,
							"",
							"男");
				
				doc_image.setImageBitmap(bm);
			}else
			{
				doc_txtIntroduction.setText("");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	

	@Override
	public DatabaseHelper getHelper(Context context) {
		
		return DatabaseAccessImplementation.getInstance().getHelper(context);
	}
}
